﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
namespace DAL
{
   public class DAL_ConsumerDetails
    {
       public static int TJ_xfjr(Model_ConsumerDetails m) {
           string sql = @"insert into  ConsumerDetail values
(@CBID,@ProdcutID,@CDPrice,@CDAmount,@CDSale,@CDMoney,0,GETDATE())";
           List<SqlParameter> list = new List<SqlParameter>{
                new SqlParameter("@CBID",m.CBID),
                 new SqlParameter("@ProdcutID",m.ProdcutID),
                  new SqlParameter("@CDPrice",m.@CDPrice),
                   new SqlParameter("@CDAmount",m.CDAmount),
                    new SqlParameter("@CDSale",m.CDSale),
                     new SqlParameter("@CDMoney",m.CDMoney),
                    
                      
           };
           return DBHelper.Update(sql, list.ToArray());

       }

       public static SqlDataReader ZQ_xfjr(Model_ConsumerBill m)
       {
           string sql = @"select ProductName,CDPrice,CDAmount,CDMoney,CDDate,PTName from ConsumerDetail AS CD
JOIN Products AS PR 
ON
CD.ProdcutID=PR.ProductID
JOIN ProductType as pt
on
PR.PTID=pt.PTID
where CBID=@CBID AND CDType =0;";
           List<SqlParameter> list = new List<SqlParameter>{
                new SqlParameter("@CBID",m.CBID)        
           };
           return DBHelper.Zhilianshi(sql, list.ToArray());

       }
       //修改重复添加的商品账单
       public static int UP_SP(Model_ConsumerDetails m)
       {
           string sql = @" UPDATE ConsumerDetail SET CDPrice=@CDPrice,CDAmount=@CDAmount,CDSale=@CDSale,CDMoney=@CDMoney 
WHERE ProdcutID=@ProdcutID AND CBID=@CBID";
           List<SqlParameter> l = new List<SqlParameter>();
           l.Add(new SqlParameter("@CDPrice", m.CDPrice));
           l.Add(new SqlParameter("@CDAmount", m.CDAmount));
           l.Add(new SqlParameter("@CDSale", m.CDSale));
           l.Add(new SqlParameter("@CDMoney", m.CDMoney));
           l.Add(new SqlParameter("@ProdcutID", m.ProdcutID));
           l.Add(new SqlParameter("@CBID", m.CBID));
           return DBHelper.Update(sql, l.ToArray());

       }
    }
}
